package com.ruoyi.web.controller.showreport;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.ReportShowtable;
import com.ruoyi.report.service.IReportShowtableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报告展示表格Controller
 * 
 * @author wry
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/showreport/showtable")
public class ReportShowtableController extends BaseController
{
    @Autowired
    private IReportShowtableService reportShowtableService;

    /**
     * 查询报告展示表格列表
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtable:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportShowtable reportShowtable)
    {
        startPage();
        List<ReportShowtable> list = reportShowtableService.selectReportShowtableList(reportShowtable);
        return getDataTable(list);
    }

    /**
     * 导出报告展示表格列表
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtable:export')")
    @Log(title = "报告展示表格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportShowtable reportShowtable)
    {
        List<ReportShowtable> list = reportShowtableService.selectReportShowtableList(reportShowtable);
        ExcelUtil<ReportShowtable> util = new ExcelUtil<ReportShowtable>(ReportShowtable.class);
        util.exportExcel(response, list, "报告展示表格数据");
    }

    /**
     * 获取报告展示表格详细信息
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtable:query')")
    @GetMapping(value = "/{tableId}")
    public AjaxResult getInfo(@PathVariable("tableId") Long tableId)
    {
        return success(reportShowtableService.selectReportShowtableByTableId(tableId));
    }

    /**
     * 新增报告展示表格
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtable:add')")
    @Log(title = "报告展示表格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportShowtable reportShowtable)
    {
        if (!reportShowtableService.checkShowTableUnique(reportShowtable))
        {
            return error("新增表格'" + reportShowtable.getReportTableName() + "'失败，报告表格名称已存在");
        }
        reportShowtable.setCreateBy(getUsername());
        return toAjax(reportShowtableService.insertReportShowtable(reportShowtable));
    }

    /**
     * 修改报告展示表格
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtable:edit')")
    @Log(title = "报告展示表格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportShowtable reportShowtable)
    {
        if (!reportShowtableService.checkShowTableUnique(reportShowtable))
        {
            return error("修改表格'" + reportShowtable.getReportTableName() + "'失败，报告表格名称已存在");
        }
        reportShowtable.setUpdateBy(getUsername());
        return toAjax(reportShowtableService.updateReportShowtable(reportShowtable));
    }

    /**
     * 删除报告展示表格
     */
    @PreAuthorize("@ss.hasPermi('showreport:showtable:remove')")
    @Log(title = "报告展示表格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tableIds}")
    public AjaxResult remove(@PathVariable Long[] tableIds)
    {
        return toAjax(reportShowtableService.deleteReportShowtableByTableIds(tableIds));
    }


}
